//
//  AssetViewModel.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/6/13.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit
typealias securityBlock = () ->()
class AssetViewModel: BaseViewModel {
    @objc dynamic var refreshBool = false //监听的状态
    
    var needRefreshCoinKind:Bool = false //是否需要刷新币种信息
    
    
    
    override init(controller: BaseViewController) {
        super.init(controller: controller)
    }
    
    

    
    
    /// 开启定时刷新价格
    func openTimer() {
        CYGCDTimer.shared.scheduledDispatchTimer(WithTimerName: "dyc", timeInterval: 60, queue: .main, repeats: true) {
            APPAssetInfo.default.updateAsset()
            self.refreshBool  = true
        }
    }
    
    func closeTimer() {
        CYGCDTimer.shared.cancleTimer(WithTimerName: "dyc")
    }

}
extension AssetViewModel: RequestCallBack,RequestDataReformer,RequestParamSource {
    func reform(_ request: BaseRequest, _ data: [String : Any]?) {
        let block = self.successBlockDic.object(forKey: request.path())
        if ((block as? success) != nil) {
            (block as! success)(data)
        }
    }
    
    func requestDidSucess(_ request: BaseRequest) {
        
    }
    
    func requestDidFail(_ request: BaseRequest) {
        let block = self.failBlockDic.object(forKey: request.path())
        if ((block as? fail) != nil) {
            (block as! fail)(request)
        }
    }
    
    func requestParams(_ request: BaseRequest) -> [String : Any]? {
        let pramas: [String:Any] = [:]
        
        return pramas
    }
    
    
    
}
